﻿(function ($) {
    "use strict";

    $("#content").SearchPage({
        url: "/dbschedule/task/getAllViewTask",
        autoRefresh:  true,
        singleRefresh: true,
        batchBtns: [
            {translateFor: 'btn.batchOpenTaskSwitch', action: 'batchChangeSwitch', arg: true},
            {translateFor: 'btn.batchCloseTaskSwitch', action: 'batchChangeSwitch', arg: false},
            {translateFor: 'btn.batchDeleteTaskSwitch', action: 'batchDelete'}
        ],
        rightBtns: [
            {translateFor: 'text.closeAllTask', icon: 'ti ti-close', action: 'changeAllSwitch', arg: false},
            {translateFor: 'text.openAllTask', icon: 'ti ti-check-box', action: 'changeAllSwitch', arg: true}
        ],
        primaryKey: 'id',
        showCode: 'taskId',
        confirmTitleReplace: 'confirm.label.task',
        columns: [
            {label: 'label.taskId', code: 'taskId', minWidth: '9.3rem', primary: true, textEllipsis: true, selector: true, order: true},
            {label: 'label.taskName', code: 'taskName', minWidth: '13.1rem', textEllipsis: true, selector: true},
            {label: 'label.taskType1', code: 'taskType', minWidth: '7.8rem', selector: true, align: 'center', translateFor: 'taskType', filter: true},
            {label: 'label.currentFireTime', code: 'currentFireTime', minWidth: '9.3rem', textEllipsis: true, selector: true, order: true},
            {label: 'label.currentFinishTime', code: 'currentFinishTime', minWidth: '9.3rem', textEllipsis: true, selector: true, order: true},
            {label: 'label.nextFireTime', code: 'nextFireTime', minWidth: '9.3rem', textEllipsis: true, selector: true, order: true},
            {label: 'label.status', code: 'status', minWidth: '8.6rem', align: 'center', selector: true, filter:true, translateFor: 'taskStatus', addClass: 'badge-text badge-text-small status', addClassFun: function(data){return data.statusLevel}},
            {label: 'label.taskSwitch1', code: 'taskSwitch', minWidth: '7.5rem', align: 'center', filter:true, switch: true, changeUrl: '/dbschedule/task/changeTaskSwitch', allChangeUrl: '/dbschedule/task/changeAllTaskSwitch', confirmCloseContent: 'confirm.warn.taskSwitchContent'},
            {type: 'action', minWidth: '9.3rem', btns: [
                {translateFor: function(data){return 'text.' + this.getPauseAction(data) + 'Task'}, action: function(data){return this.getPauseAction(data) + 'Task'}, icon: function(data){return 'la la-' + this.getPauseAction(data) + ' edit'}},
                {translateFor: 'text.showTaskDetail', action: 'showTaskDetail', icon: 'la la-edit edit'},
                {translateFor: 'text.showSubTask', action: 'showSubTask', icon: 'la la-external-link more'},
                {translateFor: 'text.removeTask', action: 'singleDelete', icon: 'la la-trash delete'}
            ]}
        ],
        deleteParams: {
            url: '/dbschedule/task/deleteTask',
            confirmContent: 'confirm.warn.deleteTaskContent',
            check: function(data) {
                return data.status != 'B' && data.status != 'RB' && data.status != 'R' && data.status != 'RR' && data.status != 'P' && data.status != 'RP';
            },
            checkFailNoty: 'message.disallowedDeleteTask'

        },
        showTaskDetail: function (data) {
            newNormalModal({
                title: 'modal.title.showTaskDetail',
                titleReplace: cdata(data.taskId),
                showFooter: false,
                data: data.id,
                modalId: 'showTaskDetail',
                hideFun: () => this.refresh()
            });
        },
        showSubTask: function (data) {
            newNormalModal({
                title: 'modal.title.showSubTask',
                titleReplace: cdata(data.taskId),
                showFooter: false,
                data: data.id,
                modalId: 'showSubTask',
                hideFun: () => this.refresh()
            });
        },
        playTask: function playTask(data, row) {
            alert('暂不可用')
        },
        pauseTask: function pauseTask(data, row) {
            alert('暂不可用')
        },
        getPauseAction: function(data) {
            return (data.status == 'P' || data.status == 'RP') ? 'play' : 'pause';
        }
    });
})(jQuery);